//Timer.h
#pragma once

#include <Arduino.h>
#include <vector>

//attachInterrupt(digitalPinToInterrupt(pin), isr, mode);



enum TIMx_INT   //0~3 有四个定时器
{
    TIM0_INT = 0,
    TIM1_INT,
    TIM2_INT,
    TIM3_INT
};

hw_timer_t *timex_Init(TIMx_INT TIM,uint32_t arr,uint16_t psc,void (*timx_ISR)(void));     /* 定时器中断初始化函数 */
hw_timer_t *timex_Init(uint8_t TIM,uint32_t arr,uint16_t psc,void (*timx_ISR)(void));


/*对ledc函数的封装,拥有8个输出通道
需要将引脚配置为 PWM 功能模式,请避免模式冲突*/
class LedcPwm
{
private:
    std::vector<uint8_t> Pins;  //存储所有绑定的引脚
    uint8_t Channel;
public:
    LedcPwm() {};
    LedcPwm(const LedcPwm &ledcPwm);
    LedcPwm(uint8_t pin,uint8_t channel,uint16_t frequency,uint8_t resolution);
    void ledcpwm_write(uint8_t duty);  //指定占空比数值
    //同一个通道可对应多个引脚,一个引脚只能绑定一个通道
    void AttachPins(uint8_t pin);
    void DetachPins();
    double ledcWriteNote(note_t note, uint8_t octave);
    LedcPwm& operator=(const LedcPwm &ledcPwm);
};



